/*
 * @Description: 系统消息管理 - 接口
 * @Author: DHL
 * @Date: 2022-11-27 15:51:45
 * @LastEditors: DHL
 * @LastEditTime: 2022-11-28 20:55:50
 */

import { $get, $post, $put, $exportExcel } from '/@/utils/http'
import { ContentTypeEnum } from '/@/constant/http'
import {
  MessageModel,
  MessageParams,
  MessagePageParams,
  MessagePageResultModel,
  MessageResultModel
} from './model/messageModel'

/**
 * 分页查询
 */
export const apiMessageSearch = (searchParams: MessagePageParams) =>
  $get<MessagePageResultModel>({
    url: '/message/search',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const apiMessageGetById = (id: string) =>
  $get<MessageResultModel>({
    url: '/message/getById',
    params: { id: id }
  })

/**
 * 保存信息
 */
export const apiMessageSave = (saveParams: MessageModel) =>
  $post<MessageResultModel>({
    url: '/message/save',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 更新信息
 */
export const apiMessageUpdateById = (updateParams: MessageModel) =>
  $put<MessageResultModel>({
    url: '/message/updateById',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })

/**
 * 批量删除信息
 */
export const apiMessageBatchDeleteByIds = (ids: string) =>
  $post<MessageResultModel>({
    url: '/message/batchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 批量逻辑删除
 */
export const apiMessageLogicBatchDeleteByIds = (ids: string) =>
  $post<MessageResultModel>({
    url: '/message/logicBatchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 导出
 */
export const apiMessageExport = (searchParams: MessageParams, fileName: string) =>
  $exportExcel<MessageResultModel>(
    {
      url: '/message/exportExcel',
      params: searchParams
    },
    fileName
  )

/**
 * 发布消息
 * @param messsageId
 * @returns
 */
export const apiMessagePublish = (messsageId: string) =>
  $post<MessageResultModel>({
    url: '/message/publish',
    contentType: ContentTypeEnum.form,
    params: {
      messsageId: messsageId
    }
  })

/**
 * 撤销发布
 * @param messsageId
 * @returns
 */
export const apiMessageCancel = (messsageId: string, revokeReason: string) =>
  $post<MessageResultModel>({
    url: '/message/cancel',
    contentType: ContentTypeEnum.form,
    params: {
      messsageId: messsageId,
      revokeReason: revokeReason
    }
  })
